<!--<script type="text/javascript" src="js/prototype.js"></script>
		<script type="text/javascript" src="js/scriptaculous.js"></script>
		<script type="text/javascript" src="js/HelpBalloon.js"></script>
		<link rel="stylesheet" type="text/css" href="css/stylex.css"></link>
		<script type="text/javascript">
		
		//
		// Override the default settings to point to the parent directory
		//
		HelpBalloon.Options.prototype = Object.extend(HelpBalloon.Options.prototype, {
			icon: 'img/icon.gif',
			button: 'img/button.png',
			balloonPrefix: 'img/balloon-'
		});
		
		//
		</script>

-->

		
<?php

$dzis=date("Y-m-d", strtotime('now'));

if($_GET['data']) 
{
$form_d=$_GET['data'];
$form_date=$form_d;
$month=date('m', strtotime($form_date));
$year=date('Y', strtotime($form_date));
$today=date('j', strtotime($form_date));
}
elseif($_SESSION['data']) 
{
$form_d=$_SESSION['data'];
$form_date=$form_d;
$month=date('m', strtotime($form_date));
$year=date('Y', strtotime($form_date));
$today=date('j', strtotime($form_date));
}

if($_GET['month']){$month=$_GET['month'];}
else {$month = (isset($month)) ? $month : date("n",time());}
$last_month = $month-1;
$next_month = $month+1;

$monthnames = array("Styczen","Luty","Marzec","Kwiecien","Maj","Czerwiec","Lipiec","Sierpien","Wrzesien","Październik","Listopad","Grudzien");
$textmonth = $monthnames[$month - 1];

if($month=='12') {
        $next_month=1;
        if($_GET['year']){$year=$_GET['year'];}
        else {$year = (isset($year)) ? $year : date("Y",time());}
        $last_year=$year;
        $next_year=$year+1;
        }
elseif ($month=='1') {
        $last_month=12;
        if($_GET['year']){$year=$_GET['year'];}
        else {$year = (isset($year)) ? $year : date("Y",time());}
        $last_year=$year-1;
        $next_year=$year;
        }
else    {
        if($_GET['year']){$year=$_GET['year'];}
        else {$year = (isset($year)) ? $year : date("Y",time());}
        $last_year=$year;
        $next_year=$year;
        }

$today = (isset($today))? $today : date("j", time());
#$today = ($month == date("n",time())) ? $today : 32;
if ( (($month < 8) && ($month % 2 == 1)) || (($month > 7) && ($month % 2 == 0)) )
$days = 31;
if ( (($month < 8) && ($month % 2 == 0)) || (($month > 7) && ($month % 2 == 1)) )
$days = 30;
if ($month == 2)
$days = (date("L",time())) ? 29 : 28;

$year_minus=$year-1;
$year_plus=$year+1;


$dayone = date("w",mktime(1,1,1,$month,1,$year));
$daylast = date("w",mktime(1,1,1,$month,$days,$year));
echo '
<table class="linia" border="1" cellpadding="0" cellspacing="0" width="90%" align="center">
<tr>
<td colspan="3" align="center"><a href="index.php?month='.$last_month.'&year='.$last_year.'"><b><<<<</b></a>&nbsp;&nbsp;&nbsp;<b>'.$textmonth.'</b>&nbsp;&nbsp;&nbsp;&nbsp;<a href="index.php?month='.$next_month.'&year='.$next_year.'"><b>>>>></b></a></td><td align="center"><a href="index.php?data='.$dzis.'"><b>Dzis</b></a></td><td colspan="3" align="center"><a href="index.php?month='.$month.'&year='.$year_minus.'"><b><<<<</b></a>&nbsp;&nbsp;&nbsp;<b>'.$year.'</b>&nbsp;&nbsp;&nbsp;<a href="index.php?month='.$month.'&year='.$year_plus.'"><b>>>>></b></td>
</tr>
<tr>
<td align="center" width="15%" class="darktable">Nd</td>
<td align="center" width="14%">Pn</td>
<td align="center" width="14%">Wt</td>
<td align="center" width="14%">Sr</td>
<td align="center" width="14%">Cz</td>
<td align="center" width="14%">Pt</td>
<td align="center" width="15%" class="darktable">So</td>
</tr>
';
if($dayone != 0)
$span1 = $dayone;
if(6 - $daylast != 0)
$span2 = 6 - $daylast;
for($i = 1; $i <= $days; $i++):
$dayofweek = date("w",mktime(1,1,1,$month,$i,$year));
$width = "14%";

if($dayofweek == 0 || $dayofweek == 6)
$width = "15%";

if($i == $today):
$fontcolor = $todayfontcolor;
$class = '4';
endif;
if($i != $today):
$fontcolor = $defaultfontcolor;
$class = '3';
endif;

if($i == 1 || $dayofweek == 0):
echo '<tr>';
if($span1 > 0 && $i == 1)
echo '<td align="center" colspan="'.$span1.'"">&nbsp;</td>';
endif;

echo '<td align="center" width="'.$width.'">';
$data=$year.'-'.data_zero($month).'-'.data_zero($i);

//$sql="select distinct sl_gab.nazwa, sl_gab.id from wizyty, pac, sl_gab, user_gab where wizyty.akt=1 and wizyty.id_gab = sl_gab.id and sl_gab.id = user_gab.id_gab and user_gab.id_user = ".$_SESSION['uzytk']['id']." and  pac.id = wizyty.id_pac and  wizyty.data like '".$data."%' order by sl_gab.nazwa";
//
//#$sql="select pac.pac_nazwisko, pac.pac_imie, DATE_FORMAT(wizyty.data, '%k:%i') as czas, sl_gab.nazwa from wizyty, pac, sl_gab, user_gab where wizyty.akt=1 and wizyty.id_gab = sl_gab.id and sl_gab.id = user_gab.id_gab and user_gab.id_user = ".$_SESSION['uzytk']['id']." and  pac.id = wizyty.id_pac and  wizyty.data like '".$data."%' order by sl_gab.nazwa, czas";
//
//#echo $sql;
//
//
//
//$result=mysql_query($sql);
//	$ile=@mysql_numrows($result);
//	unset($tresc);
//	#$tresc='Zapisanych '.$ile.' pacjentów<br><br>';
//	if ($ile>0){
//	$result=mysql_query($sql);
//	while($row = mysql_fetch_array($result))
//	{
//	$tresc=$tresc.'<b>'.$row['nazwa'].'</b><br>';
//	
//	$sql2="select distinct pac.pac_nazwisko, pac.pac_imie, DATE_FORMAT(wizyty.data, '%k:%i') as czas from wizyty, pac, sl_gab, user_gab where wizyty.akt=1 and wizyty.id_gab = sl_gab.id and sl_gab.id = user_gab.id_gab and  pac.id = wizyty.id_pac and  wizyty.data like '".$data."%' and sl_gab.id = ".$row['id']." order by sl_gab.nazwa, czas";
//	#echo $sql2.'<br>';
//	$result2=mysql_query($sql2);
//	while($row2 = mysql_fetch_array($result2))
//	{
//	$tresc=$tresc.$row2[2].'-'.$row2[0].' '.$row2[1].'<br>';
//	
//	}
//	}
//}



echo "<a ";
#echo "onMouseover=\"ddrivetip('".$tresc."')\"; onMouseout=\"hideddrivetip()\"; ";
#echo '<span id="fancy" title="Note - Please note the custom positioning here!">';
#echo "onmouseover=\"showToolTip(event,'".$tresc."');return false\" onmouseout=\"hideToolTip()\"";


echo "href=index.php?data=".$data." >";
if ($i==$today && $month==@date('m', @strtotime($form_date))) {echo '<b><font color="red">'.data_zero($i).'</b></font>';}
else {echo data_zero($i);}
echo'</a>&nbsp;&nbsp;&nbsp;';
//echo '<script type="text/javascript">
//	var hb1 = new HelpBalloon({
//		title: \''.$data.'\',
//		content: \''.$tresc.'\',
//		
//	});
//</script>';
echo '</td>';

if($i == $days):
if($span2 > 0)
echo '<td align="center" colspan="'.$span2.'">&nbsp;</td>';
endif;
if($dayofweek == 6 || $i == $days):
echo '</tr>';
endif;
endfor;
echo '</table>';
#zmienne();
?>

